<!DOCTYPE html>
<script src=../../resources/testharness.js></script>
<script src=../../resources/testharnessreport.js></script>
<script>

test(function() {
  var array = new Uint8Array([0x70, 0x71, 0x72, 0x73]);
  var blob = new Blob([array]);
  var blobEvent = new BlobEvent('BlobEvent', {data : blob});

  var reader = new FileReader();
  reader.addEventListener("loadend", function() {
    // |reader.result| contains the contents of blob as an ArrayBuffer.
    var outputArray = new Uint8Array(reader.result);
    assert_array_equals(array, outputArray)
  });
  reader.readAsArrayBuffer(blobEvent.data);
  assert_equals(blobEvent.timecode, NaN, 'timecode');

}, 'BlobEvent creation and content management');

test(function() {
  var array = new Uint8Array([0x70, 0x71, 0x72, 0x73]);
  var blob = new Blob([array]);
  var now = Date.now();
  var blobEvent = new BlobEvent('BlobEvent', {data : blob, timecode : now});

  assert_equals(blobEvent.timecode, now, 'timecode');

}, 'BlobEvent creation with timecode');

test(function() {
  assert_throws_js(TypeError,
                   function() { var blobEvent = new BlobEvent('BlobEvent'); });
}, 'BlobEvent needs two constructor parameters, type and BlobEventInit');

test(function() {
  var array = new Uint8Array([0x70, 0x71, 0x72, 0x73]);
  var blob = new Blob([array]);
  assert_throws_js(TypeError,
                   function() {
                     var blobEvent = new BlobEvent(blob, {data : "blergh"});
                   });
}, 'BlobEvent needs the second constructor parameter to be a BlobEventInit');

test(function() {
  var array = new Uint8Array([0x70, 0x71, 0x72, 0x73]);
  var blob = new Blob([array]);
  assert_throws_js(TypeError,
                   function() {
                     var blobEvent = new BlobEvent(blob, {timecode : 0.0});
                   });
}, 'BlobEventInit needs a data parameter');

</script>
